﻿@using MarkdownWeb.Models

@{
    WikiContent content = ViewData["content"] as WikiContent;

    ViewBag.Title = content.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="panel panel-info">
    <div class="panel-heading">
        <div class="row">
            <div class="col-lg-10">
                <h3>@content.Title</h3>
            </div>
        </div>       
        <div class="row">
            <div class="col-sm-1">
                <div class="btn btn-default"><a href='javascript:void(0)' id="@content.Title" class="edit">编辑</a></div>
            </div>
            <div class="col-sm-1">
                <div class="btn btn-danger"><a href='javascript:void(0)' id="@content.Title" class="delete">删除</a></div>
            </div>
        </div>
    </div>    
    <div class="panel-body" id="result"></div>
</div>

<div id="temptext" style="position:absolute;display:none">@content.Content
</div>



@section scripts{

    <script src="~/Scripts/showdown.min.js"></script>
    <script type="text/javascript">
    window.onload = function () {
        compile();
    }
    $(document).ready(function () {

        $(".delete").click(function (e) {
            if (!confirm("确定要删除吗？"))
                return;
            var id = e.target.id;
            //执行删除
            $.post("/Content/Delete", { ID: id }, function (resultMsg) {
                if (resultMsg == 'ok') {
                    alert("删除成功");
                    location.href = "/首页";
                }
                else {
                    alert("删除失败！");
                    location.href = "/首页";
                }
            });
        });
        $(".edit").click(function (e) {
            var id = e.target.id;
            var url = "/edit/index?title="+id;

            location.href = url;
        });

    });
    function compile() {
        var text = document.getElementById("temptext").textContent;
        var converter = new showdown.Converter();
        var html = converter.makeHtml(text);
        document.getElementById("result").innerHTML = html;
    }
</script>
}